<!--佣金结算-->
<template>
  <div class="app-container">
    <el-card>
      <div class="topCardStyle">
        <div class="topItem" v-for="(v, i) in statisticsList" :key="i">
          <div>{{ v.nowValue }}</div>
          <div>{{ v.text }}</div>
        </div>
      </div>
    </el-card>

    <el-card style="margin-top: 20px">
      <el-form size="small" :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="产品名称">
          <el-input v-model="searchForm.productName" placeholder="请输入产品名称"></el-input>
        </el-form-item>
        <el-form-item label="订单编号">
          <el-input v-model="searchForm.orderNo" placeholder="请输入订单编号"></el-input>
        </el-form-item>
        <el-form-item label="订单来源">
          <el-select v-model="searchForm.channelId" clearable placeholder="请选择">
            <el-option v-for="item in productChannelList" :key="item.label" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户经理">
          <el-select v-model="searchForm.managerId" clearable placeholder="请选择">
            <el-option v-for="item in managerList" :key="item.id" :label="item.name + ' ' + '(' + item.phone + ')'"
              :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="结算状态">
          <el-select v-model="searchForm.stlmtState" clearable placeholder="请选择">
            <el-option v-for="item in stateWayList" :key="item.label" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查询时间：" prop="beginTime">
          <el-date-picker style="width: 200px" v-model="searchForm.beginTime" align="right" type="date"
            placeholder="选择开始日期" :picker-options="$pickerDateOptions" value-format="yyyy-MM-dd"
            format="yyyy 年 MM 月 dd 日">
          </el-date-picker>
        </el-form-item>
        <el-form-item>-</el-form-item>
        <el-form-item prop="endTime">
          <el-date-picker style="width: 200px" v-model="searchForm.endTime" align="right" type="date"
            placeholder="选择结束日期" :picker-options="$pickerDateOptions" value-format="yyyy-MM-dd"
            format="yyyy 年 MM 月 dd 日">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-refresh" @click="reset">重置</el-button>
          <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="listLoading" :data="tableData.list" border size="small">
        <!--<el-table-column type="selection" width="55" align="center" fixed></el-table-column>-->
        <el-table-column type="index" width="55" label="序号" align="center" fixed></el-table-column>
        <el-table-column label="结算单号" prop="stlmtNo" align="center" width="120" fixed></el-table-column>
        <el-table-column label="订单编号" align="center" width="120" fixed>
          <template slot-scope="scope">
            <span @click="orderNumClick(scope.row)" style="color: #419eff;cursor:pointer;">
              {{ scope.row.orderNo }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="订单时间" prop="orderCreateTime" align="center" width="180"></el-table-column>
        <el-table-column label="订单来源" prop="channelId" align="center" width="120"></el-table-column>
        <el-table-column label="订单进度" prop="orderState" align="center" width="120"></el-table-column>
        <el-table-column label="订单产品" align="center" width="160">
          <template slot-scope="scope">
            <router-link :to="{
              path: '/productDetail',
              query: { id: scope.row.productId }
            }" class="link-type">
              <span style="color: #419eff;cursor: pointer">{{
                scope.row.productName
              }}</span>
            </router-link>
          </template>
        </el-table-column>
        <el-table-column label="客户信息" prop="customerInformation" align="center" width="180">
          <template slot-scope="scope">
            <div>
              {{ scope.row.name }}
            </div>
            <div>{{ scope.row.phone }}</div>
            <div>{{ scope.row.companyName }}</div>
          </template>
        </el-table-column>
        <el-table-column label="授信金额（元）" prop="creditMoney" align="center" width="120"></el-table-column>
        <el-table-column label="放款金额（元）" prop="loanMoney" align="center" width="120"></el-table-column>
        <el-table-column label="所属客户经理" prop="managerName" align="center" width="120"></el-table-column>
        <el-table-column label="结算节点" prop="stlmtNode" align="center" width="120"></el-table-column>
        <el-table-column label="结算金额（元）" prop="managerId" align="center" width="120"></el-table-column>
        <el-table-column label="结算方式" prop="stlmtMethod" align="center"></el-table-column>
        <el-table-column label="结算状态" prop="stlmtState" align="center"></el-table-column>
        <el-table-column label="服务费总额" prop="servTotalAmount" align="center" width="120"></el-table-column>
        <el-table-column label="已结算服务费" prop="servSettledAmount" align="center" width="120"></el-table-column>
        <el-table-column label="预结算服务费" prop="servPreSettledAmount" align="center" width="120"></el-table-column>
        <el-table-column label="修改时间" prop="updateTime" align="center" width="190"></el-table-column>
        <el-table-column label="操作" width="200" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button v-if="parseFloat(scope.row.servPreSettledAmount) > 0" type="text"
              @click="editClick(scope.row)">结算</el-button>
            <el-button type="text" @click="detailClick(scope.row)">详情</el-button>
            <el-button type="text" @click="customClick(scope.row)">客户信息</el-button>
            <el-button type="text" @click="settlDetailClick(scope.row)">结算规则详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination class="pageRight" background layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[10, 20, 50, 100]" :page-size="searchForm.pageSize" :total="tableData.total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange"></el-pagination>
    </el-card>
    <!--编辑-->
    <edit ref="edit" :settlementMethodList="paymentwWayList" :detailInfo="detailInfo" @cancel="cancelEdit"></edit>
    <!--客户信息-->
    <manager-detail :detailInfo="detailInfo" :show="managerDetailDialogShow" @cancel="cancelManDetail"></manager-detail>
    <!--订单编号详情-->
    <!--    <order-detail :show="orderDialogShow" @cancel="cancelOrder"></order-detail>-->
    <!--结算规则详情-->
    <rules-dialog :key="keyRule" :show="rulesDialogShow" :detailInfo="detailInfo" @cancel="cancelRules"></rules-dialog>
    <!--详情-->
    <detail :detailInfo="detailInfo" :show="detailDialogShow" :productChannelList="productChannelList"
      :settlementMethodList="settlementMethodList" @cancel="cancelDetail"></detail>
    <orderdetail ref="orderdetail"></orderdetail>
  </div>
</template>

<script>
import edit from "./component/edit.vue";
import managerDetail from "./component/managerDetail.vue";
import OrderDetail from "./component/orderDetail.vue";
import rulesDialog from "../settlementRules/rulesDialog.vue";
import Detail from "../commissionSettlement/component/detail.vue";
import { getCommissionList, getBillStatistics } from "@/api/commission";
import { getDictLabel } from "@/utils/dict";
import { getCustomerManagerList } from "../../../api/customer";

import orderdetail from "../../incomingManagement/onLine/components/detail.vue";
const defaultSearchForm = {
  pageNum: 1,
  pageSize: 10,
  productName: "",
  orderNo: "",
  channelId: "",
  managerId: "",
  stlmtState: ""
};
export default {
  components: {
    orderdetail,
    Detail,
    OrderDetail,
    edit,
    managerDetail,
    rulesDialog
  },
  data() {
    return {
      searchTime: [],
      searchForm: defaultSearchForm,
      stateWayList: [
        {
          label: "待初审",
          value: "待初审"
        },
        {
          label: "初审不通过",
          value: "初审不通过"
        },
        {
          label: "待复审",
          value: "待复审"
        },
        {
          label: "复审不通过",
          value: "复审不通过"
        },
        {
          label: "复审通过",
          value: "复审通过"
        }
      ], //结算状态
      stateList: [], //计件类型
      orderSourceList: [], // 订单来源
      managerList: [], //客户经理
      listLoading: false,
      tableData: {
        total: 0,
        list: []
      },
      detailInfo: {},
      editDialogShow: false,
      detailDialogShow: false,
      orderDialogShow: false,
      rulesDialogShow: false,
      managerDetailDialogShow: false,
      keyRule: 0,
      settlementMethodList: [], //结算方式
      stlmtnodeList: [],
      pieceTypeList: [],
      statisticsList: [],
      productChannelList: [],
      paymentwWayList: []
    };
  },
  async created() {
    this.settlementMethodList = await this.$getDictData("settlement_method");
    this.stlmtnodeList = await this.$getDictData("stlmt_node");
    this.pieceTypeList = await this.$getDictData("piece_type");
    this.productChannelList = await this.$getDictData("product_channel");
    this.paymentwWayList = await this.$getDictData("payment_way");
    this.getCustomerManagerList();
    this.getList();
    this.getBillStatisticsInfo();
  },
  methods: {
    getCustomerManagerList() {
      getCustomerManagerList().then(res => {
        this.managerList = res.data.map(v => {
          return {
            name: v.nickName,
            id: v.adminId,
            phone: v.phoneNumber
          };
        });
      });
    },
    search() {
      this.searchForm.pageNum = 1;
      this.$authDate(this.searchForm.beginTime, this.searchForm.endTime, v => {
        if (!v.type) {
          return this.$message.warning(v.msg);
        } else {
          // console.log(this.searchForm);
          this.getList();
        }
      });
    },
    getBillStatisticsInfo() {
      getBillStatistics().then(res => {
        this.statisticsList = res.data;
      });
    },
    reset() {
      this.searchTime = [];
      this.searchForm = {
        pageNum: 1,
        pageSize: 10,
        productName: "",
        orderNo: "",
        channelId: "",
        managerId: "",
        stlmtState: ""
      };
      this.getList();
    },
    getList() {
      this.listLoading = true;
     
      getCommissionList(this.searchForm)
        .then(res => {
          res.data.list.forEach(item => {
            item.channelId = getDictLabel(
              item.channelId,
              this.productChannelList
            );

            item.stlmtMethod = getDictLabel(
              item.stlmtMethod,
              this.settlementMethodList
            );
            item.stlmtNode = getDictLabel(item.stlmtNode, this.stlmtnodeList);
          });
          this.tableData.total = res.data.total;
          this.tableData.list = res.data.list;
          this.listLoading = false;
        })
        .finally(() => {
          this.listLoading = false;
        });
    },
    // 编辑
    editClick(v) {
      this.$refs.edit.opendialog(v);
      // this.detailInfo = v;
      // this.editDialogShow = true;
    },
    cancelEdit(val) {
      // this.detailInfo = val;
      this.editDialogShow = val;
      this.getList();
    },
    // 详情
    detailClick(v) {
      this.detailInfo = v;
      this.detailDialogShow = true;
    },
    cancelDetail(val) {
      this.detailDialogShow = val;
    },
    // 客户信息
    customClick(v) {
      this.detailInfo = v;
      this.managerDetailDialogShow = true;
    },
    cancelManDetail(val) {
      this.managerDetailDialogShow = val;
    },
    // 结算规则详情
    settlDetailClick(v) {
      this.detailInfo = v;
      this.rulesDialogShow = true;
    },
    cancelRules(val) {
      this.rulesDialogShow = val;
      this.keyRule++;
    },
    // 订单编号
    orderNumClick(v) {
      this.$refs.orderdetail.opendialog(v);
      // this.orderDialogShow = true;
    },
    cancelOrder(val) {
      this.orderDialogShow = val;
    },

    handleSizeChange(val) {
      this.searchForm.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.searchForm.pageNum = val;
      this.getList();
    }
  }
};
</script>

<style lang="scss" scoped>
.topCardStyle {
  display: flex;
  justify-content: space-around;

  .topItem {
    width: 25%;
    text-align: center;
    border-right: 1px solid #eeeeee;

    div {
      &:nth-child(1) {
        font-weight: 500;
        color: #222222;
        font-size: 32px;
      }

      &:nth-child(2) {
        color: #999999;
        font-size: 16px;
        margin-top: 10px;
      }
    }
  }

  .topItem:last-child {
    border-right: none;
  }
}
</style>
